package com.weetop.cfw.base.presenter.imp

import com.blankj.utilcode.util.LogUtils
import com.weetop.cfw.base.presenter.WorkshopDetailPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.WorkshopDetailView
import com.weetop.cfw.bean.ErrorBean
import com.weetop.cfw.bean.LeaseSaleBrowsingRecordBean
import com.weetop.cfw.bean.WorkshopWarehouseDetailBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.kind.activity.WorkshopDetailActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class WorkshopDetailPresenterImp(var workshopDetailView: WorkshopDetailView? = null):WorkshopDetailPresenter {

    /**
     * 获取厂房详情
     */
    override fun getWorkshopDetailData(workshopDetailActivity: WorkshopDetailActivity, infoid: Int) {
      //  workshopDetailActivity.showLoadingDialog(workshopDetailActivity,"正在获取厂房详情信息...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().workshopWarehouseDetailData(infoid),workshopDetailActivity,object:RxJavaCallBack<WorkshopWarehouseDetailBean>(){
            override fun onSuccess(t: WorkshopWarehouseDetailBean?) {
             //   workshopDetailActivity.dismissLoadingDialog()
                workshopDetailView?.workShopGetSuccess(t)
            }

            override fun onRequestError(t: WorkshopWarehouseDetailBean?) {
                super.onRequestError(t)
              //  workshopDetailActivity.dismissLoadingDialog()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
               // workshopDetailActivity.dismissLoadingDialog()
            }
        })
    }

    /**
     * 上传厂房仓库租售浏览记录
     * @param infoid 厂房仓库的ID
     */
    override fun uploadUserRentSaleBrowseRecordData(workshopDetailActivity: WorkshopDetailActivity, infoid: String) {
       RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().uploadUserRentSaleBrowseRecordData(infoid = infoid),workshopDetailActivity,object:RxJavaCallBack<ErrorBean>(){
           override fun onSuccess(t: ErrorBean?) {
               if(t != null){
                   LogUtils.dTag("上传厂房仓库浏览记录",t.message)
               }
           }

           override fun onRequestError(t: ErrorBean?) {
               super.onRequestError(t)
               if(t != null){
                   LogUtils.dTag("上传厂房仓库浏览记录",t.message)
               }
           }
       })
    }

    /**
     * 获取厂房详情推荐数据
     */
    override fun getRecommendWorkshopData(workshopDetailActivity: WorkshopDetailActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getRecommendWorkshopWareHouseData(),workshopDetailActivity,object:RxJavaCallBack<LeaseSaleBrowsingRecordBean>(){
            override fun onSuccess(t: LeaseSaleBrowsingRecordBean?) {
                workshopDetailView?.recommendWorkshopDataGetSuccess(t)
            }
        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        workshopDetailView = baseView as? WorkshopDetailView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        workshopDetailView = null
    }
}